package com.product.magina.webserviceclient.service.impl;

import com.alibaba.fastjson.JSON;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.junit.Test;

/**
 * webservice客户端
 * 
 * 
 * @author：anti_magina
 * @date：2019-03-29 16:49:26
 */
public class WebServiceTest {

    private static String WSDL_URL = "http://localhost:8081/services/TestService?wsdl";

    @Test
    public void testSend1() {
        JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
        Client client = dcf.createClient("http://localhost:8081/services/TestService?wsdl");
        // 需要密码的情况需要加上用户名和密码
        // client.getOutInterceptors().add(new ClientLoginInterceptor(USER_NAME,PASS_WORD));
        Object[] objects = new Object[0];
        try {
            DemoModel model = new DemoModel();
            model.setId("id000001");
            model.setUserName("I am id000001!");
            String json = JSON.toJSONString(model);
            // invoke("方法名",参数1,参数2,参数3....);
            Object[] objArray = new Object[2];
            objArray[1] = json;
            objArray[0] = "001";
            objects = client.invoke("sendMessageById", objArray);
            // invoke("方法名",参数1,参数2,参数3....);
//            objects = client.invoke("sendMessage", "Magina");
            System.out.println("返回数据:" + objects[0]);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

        @Test
    public void testJDData() {
        // 创建动态客户端
        JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
        Client client = dcf.createClient("http://192.168.8.99:2890/ormrpc/services/EASLogin?wsdl");

        // 需要密码的情况需要加上用户名和密码
        // client.getOutInterceptors().add(new ClientLoginInterceptor(USER_NAME,PASS_WORD));
        Object[] objects = new Object[0];
        try {

            // invoke("方法名",参数1,参数2,参数3....);
            objects = client.invoke("EASLogin", "easb","1","eas","test1108","L2",1);
            System.out.println(objects);
            System.out.println("返回数据:" + objects[0]);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
